{include file="public/nheader"}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="账号" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="添加"
                            data-area="60%,80%" data-url="/store/user_edit">添加用户
                        </button>
                    </div>

                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- <script type="text/html" id="tableBar1">
</script> -->
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" data-title="操作资产" data-area="30%,40%" callback="edits" data-url="#adminforms" lay-event="edit">修改资产</a>
    <a style="color:blue" class="layui-table-text" lay-open data-title="明细" data-area="60%,80%" data-url="/store/moneylog?user_id={{d.id}}" >消费明细</a>
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>账号:</label>
                    <div class="layui-input-block">
                        <input name="mobile" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>可用金额:</label>
                    <div class="layui-input-block">
                        <input name="money" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>类型:</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="1" title="充值" checked>
                    <input type="radio" name="type" value="2" title="消费">
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>变更金额:</label>
                <div class="layui-input-block">
                    <input name="moneys" value=""  placeholder="增减金额" type="number" class="layui-input" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>操作说明:</label>
                <div class="layui-input-block">
                    <textarea name="desc" placeholder="请输入内容" class="layui-textarea" lay-verify="required" ></textarea>
                </div>
            </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {
                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                var index = layer.load(1); //换了种风格           
                layui.$.post("{:url('store/money_edit')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                    else {
                        layer.error(res.msg);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                }, 'json');
                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , where: {
                storeid: "{:input('storeid/d',0)}", mobile: "{:input('mobile/s')}"
            }
            , toolbar: 'false'
            // , defaultToolbar: ["filter","exports","print"]
            , defaultToolbar: [{
                title: '导出excel' //标题
                , layEvent: 'LAYTABLE_EXPORT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-export' //图标类名
            }, {
                title: '打印页面' //标题
                , layEvent: 'LAYTABLE_PRINT' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-print' //图标类名
            }, {
                title: '筛选数据' //标题
                , layEvent: 'LAYTABLE_COLS' //事件名，用于 toolbar 事件中使用
                , icon: 'layui-icon-cols' //图标类名
            }]
            , even: true
            , loading: true
            , limit: 10
            , cols: [[
                // { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                {
                    field: 'name', align: 'center', width: 200, templet: function (d) {
                        return d.mobile + '(' + d.name + ')';
                    }, title: '账号信息'
                },
                { field: 'money', width: 150, align: 'center', title: '余额' },
                { field: 'created', width: 200, align: 'center', title: '注册时间' },
                { align: 'center', width: 200, toolbar: '#tableBar', title: '操作' },

            ]]
        })
    })
</script>